<?php

$sql_server = "127.0.0.1";
$port = '3306';
$sql_user = "root";
$sql_pass = "{{ admin_password }}";

$mydb="workshop";

$error = '';

try {
  $db = new \PDO("mysql:host=$sql_server;port=$port;dbname=$mydb;charset=utf8", $sql_user, $sql_pass);
} catch(PDOException $e) {
  echo "Could not connect to the database\n";
  exit;
}

if (!$db) {
  echo "Could not connect to the database\n";
  exit;
}

session_start();

// Password authentication check
$password_authenticated = false;
if (isset($_SESSION['password_authenticated']) && $_SESSION['password_authenticated'] === true) {
  $password_authenticated = true;
} elseif (isset($_POST['site_password'])) {
  if ($_POST['site_password'] === "{{ admin_password }}") {
    $_SESSION['password_authenticated'] = true;
    $password_authenticated = true;
    // Redirect to the same page to clear the POST data
    header("Location: " . $_SERVER['REQUEST_URI']);
    exit;
  } else {
    $error = '<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color=red>Incorrect password</font>';
  }
}

// Only process the login form if password authentication is complete
if ($password_authenticated) {
  if (!isset($_SESSION['email'])) {
    if (!isset($_POST['email'])) {
    } else {
      if (!isValidEmail($_POST['email'])) {
        $error = '<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color=red>Email is invalid</font>';
      } else {
        // Check if student already exists
        $student = db_fetch_assoc_prepare("SELECT * FROM `users` WHERE email = ?", array(sql_clean_username($_POST['email'])));
        if (!isset($student['id'])) {
          $id = db_fetch_cell("SELECT id FROM `users` WHERE email = '' LIMIT 1", 'id');
          if (!$id) {
            $error = '<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color=red>Sorry, all available student accounts are taken.  Please let the instructor know.</font>';
          } else {
            db_execute_prepare('UPDATE `users` set name=?, email=? WHERE id = ?', array(sql_clean_username($_POST['name']), sql_clean_username($_POST['email']), $id));
            $_SESSION['email'] = sql_clean_username($_POST['email']);
            Header("Location: /#studentinfo\n\n");
            exit;
          }
        } else {
          $_SESSION['email'] = $student['email'];
          Header("Location: /#studentinfo\n\n");
          exit;
        }
      }
    }
  } else {
    $student = db_fetch_assoc_prepare("SELECT * FROM `users` WHERE email = ?", array($_SESSION['email']));
    if (!isset($student['id'])) {
      session_destroy();
      header("Location: index.php\n\n");
      exit;
    }
  }

  if (isset($_GET['logout']) || (isset($student['email']) && $student['email'] != $_SESSION['email'])) {
    session_destroy();
    header("Location: index.php\n\n");
    exit;
  }
}
?>
<!DOCTYPE html>
<html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
  <link rel="stylesheet" href="style.css">
  <style>
    #password-form {
      background: white;
      padding: 30px;
      border-radius: 8px;
      box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
      text-align: center;
      max-width: 400px;
      margin: 50px auto;
    }
    #password-form input, #password-form button {
      padding: 10px;
      margin: 10px 0;
      width: 100%;
      box-sizing: border-box;
    }
    #password-form button {
      background-color: #4CAF50;
      color: white;
      border: none;
      cursor: pointer;
    }
    #password-form button:hover {
      opacity: 0.8;
    }
    /* Hide main content until password is entered */
    <?php if (!$password_authenticated) { ?>
    .wrapper > header, .wrapper > section, .wrapper > footer {
      display: none;
    }
    <?php } ?>
  </style>
</head>

<body>
  <div class="wrapper">
    <?php if (!$password_authenticated) { ?>
    <!-- Password Form -->
    <div id="password-form">
      <h2>Password Required</h2>
      <p>Please enter the password to access this workshop:</p>
      <form method="POST">
        <input type="password" name="site_password" id="site-password" placeholder="Enter password">
        <?php if ($error) { echo $error; } ?>
        <button type="submit">Submit</button>
      </form>
    </div>
    <?php } else { ?>
    <header>
      <div class="header-container">
        <a href="https://ansible.com">
          <img
            class="header-logo"
            src="redhat-ansible-logo.svg"
            title="Red Hat Ansible"
            alt="Red Hat Ansible"
          />
        </a>
        <a class="header-link" href="https://labs.demoredhat.com/">
          Workshops Homepage
        </a>
      </div>
    </header>

<section>
  <h1>Workshop Name: {{ec2_name_prefix}}</h1>
  <p> This is the workshop launch page.  If you require more information please refer to this <a href="https://youtu.be/Y_Gx4ZBfcuk">YouTube video</a>.</p>
    <div class="container">
        <div class="row">
            <div class="col-sm-8">
                {% if workshop_type == 'network' %}
                <h2>Ansible Automation Platform + Network</h2>
                <p>The Ansible network automation workshop is a comprehensive beginners guide to automating popular network data center devices from Arista, Cisco and Juniper via Ansible playbooks. You'll learn how to pull facts from devices, build templated network configurations, and apply these concepts at scale with Ansible automation controller. You'll put it all together by exploring the controller's job templates, surveys, access controls and more. </p>
                <div class="row">
                  <div class="col-sm-4">
                      <a target=_blank href="https://labs.demoredhat.com/exercises/ansible_network/">Network Exercises</a>
                  </div>

                  <div class="col-sm-4">
                      <a target=_blank href="https://labs.demoredhat.com/decks/ansible_network.pdf">Network Presentation Deck</a>
                  </div>

                </div>
                {% elif workshop_type == "f5" %}
                <h2>Ansible Automation Platform + F5</h2>
                <p>The Ansible F5 Networking workshop provides exercises that demonstrate Ansible Automation Platform capabilities to automate the F5 BIG-IP platform. You will be exploring, configuring and managing F5 BIG-IP instances via Ansible playbooks and extending them to Ansible automation controller for enterprise use cases.</p>
                <div class="row">
                  <div class="col-sm-4">
                      <a target=_blank href="https://labs.demoredhat.com/exercises/ansible_f5">Ansible F5 Exercises</a>
                  </div>

                  <div class="col-sm-4">
                      <a target=_blank href="https://labs.demoredhat.com/decks/ansible_f5.pdf">Ansible F5 Deck</a>
                  </div>
                </div>
                {% elif create_cluster|bool and workshop_type == "rhel" %}
                <h2>Automation controller Advanced Workshops</h2>
                <p>These workshops are focused on using advanced features of automation controller like clustering.</p>
                <div class="row">
                    <div class="col-sm-4">
                        <a target=_blank href="https://red.ht/advanced_tower">Automation controller Advanced Exercises</a>
                    </div>
                </div>
                {% elif workshop_type == 'rhel' %}
                <h2>Ansible Automation Platform + RHEL</h2>
                <p>If you're new to Ansible Automation, this workshop consists of two parts: 1) starting with the basics of understanding foundational command line activities and 2) applying what you've learned to implement Ansible automation controller to your enterprise use cases. You'll start off by writing your first Ansible playbook, work on Jinja templates, and implement higher-level Ansible roles. Next you'll get started on automation controller, understand inventory and credential management, projects, job templates, surveys, workflows and more.</p>
                <div class="row">
                    <div class="col-sm-4">
                        <a target=_blank href="https://labs.demoredhat.com/exercises/ansible_rhel/">Ansible RHEL Exercises</a>
                    </div>
                    <div class="col-sm-4">
                        <a target=_blank href="https://labs.demoredhat.com/decks/ansible_rhel.pdf">Ansible Technical Deck</a>
                    </div>
                </div>
                {% elif workshop_type == 'rhel_90' %}
                <div class="row">
                    <div class="col-sm-4">
                        <a target=_blank href="https://labs.demoredhat.com/exercises/ansible_rhel_90/">Ansible RHEL Exercises</a>
                    </div>
                    <div class="col-sm-4">
                        <a target=_blank href="https://labs.demoredhat.com/decks/ansible_rhel_90.pdf">Ansible Technical Deck</a>
                    </div>
                </div>
                {% elif workshop_type == 'security' %}
                <h2>Ansible Automation Workshop + Security</h2>
                <p>Get started with Ansible Security Automation by implementing automation for three security use cases: 1) orchestrating firewalls, 2) IDS and SIEM: investigating suspicious traffic on a web server, and 3) threat hunting: analyzing unusual denied accesses on a firewall and remediation of a SQL injection. After a brief introduction, you'll tackle some of the basic concepts and show you how to use Ansible Security Automation in combination with existing third-party security solutions.</p>
                <div class="row">
                    <div class="col-sm-4">
                        <a target=_blank href="https://labs.demoredhat.com/exercises/ansible_security">Ansible Security Exercises</a>
                    </div>
                    <div class="col-sm-4">
                        <a target=_blank href="https://labs.demoredhat.com/decks/ansible_security.pdf">Ansible Security Deck</a>
                  </div>
                </div>
                {% elif workshop_type == 'windows' %}
                <h2>Ansible Automation Platform + Windows</h2>
                <p>This workshop guides you through configuring Ansible automation controller to connect to Windows Server instances for automating various operational tasks. Once Ansible automation controller is configured, you will start with automating simple tasks and then progress to more advanced use cases such as patching and leveraging third-party solutions to enhance automation (Chocolatey). There are minimal client requirements for you to interact with the workshop because you only need a compatible Web browser. This workshop has reduced requirements for Linux knowledge and other command line tools.</p>
                <div class="row">
                    <div class="col-sm-4">
                        <a target=_blank href="https://labs.demoredhat.com/exercises/ansible_windows/">Ansible Windows Exercises</a>
                    </div>
                    <div class="col-sm-4">
                        <a target=_blank href="https://labs.demoredhat.com/decks/ansible_windows.pdf">Ansible Windows Deck</a>
                  </div>
                </div>
                {% elif workshop_type == 'configascode' %}
                <h2>Configuration as Code on Ansible Automation Platform</h2>
                <p>This Presentation/lab will provide code to demonstrate how to use CasC to maintain all aspects of AAP. The provided code will be a starting point, and will guide the user through how to utilize the code, and make it their own. This session will cover configuring controller, private automation hub, execution environments, and custom collections as well as the creation of workflows without the GUI as an example to follow along. These principles will help to prevent drift in configuration, allow changes to require approval before implementation, and help to maintain both a development and prod deployment.</p>
                <div class="row">
                    <div class="col-sm-4">
                        <a target=_blank href="https://labs.demoredhat.com/exercises/instruqt/aapcasc">Configuration as Code Workshop</a>
                    </div>
                    <div class="col-sm-4">
                        <a target=_blank href="https://github.com/ansible/workshops/tree/devel/exercises/ansible_config_as_code/">Workshop Git Repo</a>
                  </div>
                </div>
                {% elif workshop_type == 'ripu' %}
                <h2>Ansible Automation Platform + RIPU</h2>
                <p>This workshop will introduce a comprehensive approach to automate in-place upgrades for Red Hat Enterprise Linux (RHEL). The solution uses Ansible Automation to enable upgrades to be executed at enterprise scale across a large estate of RHEL hosts. The workshop demonstrates how to use an example of this approach to perform upgrades from RHEL7 to RHEL8 and from RHEL8 to RHEL9. You will also learn about how this solution can be customized to meet the special requirements of your enterprise environment.</p>
                <div class="row">
                    <div class="col-sm-4">
                        <a target=_blank href="https://labs.demoredhat.com/exercises/ansible_ripu/">Ansible RIPU Exercises</a>
                    </div>
                    <div class="col-sm-4">
                        <a target=_blank href="https://labs.demoredhat.com/decks/ansible_ripu.pdf">Ansible Technical Deck</a>
                    </div>
                </div>
                {% elif workshop_type == 'smart_mgmt' %}
                <h2>Ansible Automation Platform + Satellite</h2>
                <p>The Automate Smart Management Workshop is a half-day, hands-on workshop covering Red Hat Ansible Automation Platform, Red Hat Satellite, Red Hat Enterprise Linux and CentOS Linux. Attendees will learn how to use Ansible to automate configuration of Red Hat Ansible Automation Platform controller and Red Hat Satellite, and acquire the skills needed to implement Ansible Automation at their organizations. This workshop is comprised of 4 areas of focus:</p>
                <ul>
                  <li>How to implement Infrastructure as Code automation with Red Hat solutions</li>
                  <li>Compliance (OpenSCAP Scanning) and Vulnerability Management</li>
                  <li>OS Patch/Package Management at scale</li>
                  <li>CentOS to RHEL conversion at scale</li>
                </ul>
                <br>
                <div class="row">
                    <div class="col-sm-4">
                        <a target=_blank href="https://labs.demoredhat.com/exercises/rhdp_auto_satellite/">Automate Smart Management Exercises</a>
                    </div>
                    <div class="col-sm-4">
                        <a target=_blank href="https://labs.demoredhat.com/decks/ansible_auto_satellite.pdf">Automate Smart Management Deck</a>
                  </div>
                </div>
                {% elif workshop_type == 'auto_satellite' %}
                <h2>Ansible Automation Platform + Satellite</h2>
                <p>The Automate Satellite Workshop is a half-day, hands-on workshop covering Red Hat Ansible Automation Platform, Red Hat Satellite, Red Hat Enterprise Linux and CentOS Linux. Attendees will learn how to use Ansible to automate configuration of Red Hat Ansible Automation Platform controller and Red Hat Satellite, and acquire the skills needed to implement Ansible Automation at their organizations. This workshop is comprised of 4 areas of focus:</p>
                <ul>
                  <li>How to implement Infrastructure as Code automation with Red Hat solutions</li>
                  <li>Compliance (OpenSCAP Scanning) and Vulnerability Management</li>
                  <li>OS Patch/Package Management at scale</li>
                  <li>CentOS to RHEL conversion at scale</li>
                  <li>Vulnerability Management with Insights</li>
                </ul>
                <br>
                <div class="row">
                    <div class="col-sm-4">
                        <a target=_blank href="https://labs.demoredhat.com/exercises/rhdp_auto_satellite/">Automate Smart Management Exercises</a>
                    </div>
                    <div class="col-sm-4">
                        <a target=_blank href="https://labs.demoredhat.com/decks/ansible_auto_satellite.pdf">Automate Smart Management Deck</a>
                  </div>
                </div>
                {% endif %}
            </div>
        </div>

<br><br>

    </div>
</section>

<hr>


<section>
    <div class="container">
        <div class="row">
            <div class="col-sm-8">
                <h2>Workbench Information</h2>
                <p><?php print $error ?></p>
                <a id=studentinfo></a>
            </div>
        </div>



<?php

if (isset($student['id'])) {
  display_student($student);

} else {
  display_form();
}
?>

    </div>
</section>

</section>

<footer>
  <div class="footer-container">
    <a href="https://redhat.com">
      <img
        class="footer-logo"
        src="redhat-logo.svg"
        title="Red Hat"
        alt="Red Hat"
      />
    </a>
    <p class="footer-copyright">Copyright © 2022 Red Hat, Inc.</p>
    <div class="footer-linkContainer">
      <a href="https://www.redhat.com/en/about/privacy-policy" class="footer-link">Privacy statement</a>
      <span class="footer-linkSpacer">|</span>
      <a href="https://www.redhat.com/en/about/terms-use" class="footer-link">Terms of use</a>
      <span class="footer-linkSpacer">|</span>
      <a href="https://www.ansible.com/security?hsLang=en-us" class="footer-link">Security disclosure</a>
      <span class="footer-linkSpacer">|</span>
      <a href="https://www.redhat.com/en/about/all-policies-guidelines" class="footer-link">All policies and guidelines</a>
    </div>
  </div>
</footer>
<?php } ?>
</div>

</body>
</html>



<?php

function display_student($student) {
  print "<div class='student_logins'>
    <div class='header'>
        <p class='studentinfo'>" . ucfirst($student['username']) . "</p></div>
      <div class='content'>
        <p>
  {% if code_server is defined and code_server %}
  <div id='section_title'>VS Code access</div>
  To login to Visual Studio Code via your web browser please go here:<br>
  <table>
    <tr>
      <td>WebUI link:</td>
      <td>{% if workshop_type == 'windows' %}<a target=_blank href='" . $student['vscode'] . "'>" . $student['vscode_display'] . "</a>{% else %}<a target=_blank href='" . $student['vscode_display'] . "'>" . $student['vscode_display'] . "</a>{% endif %}</td>
    </tr>
    <tr>
      <td>password:</td>
      <td><code>" . $student['password'] . "</code></td>
    </tr>
  </table>";

  {% endif %}
  {% if workshop_type == "windows" or workshop_type == "configascode" %}
  print '<div id="section_title">Git access</div>
  To login to the git server via your web browser please go here:<br>
  <table>
    <tr>
      <td>WebUI link:</td>
      <td><a target=_blank href="' . $student['gitlab'] . '">' . $student['gitlab'] . '</a></td>
    </tr>
    <tr>
      <td>username:</td>
      <td><code>student' . $student['id'] . '</code></td>
    </tr>
    <tr>
      <td>password:</td>
      <td><code>' . $student['password'] . '</code></td>
    </tr>
  </table><br>';

  {% endif %}

  print '<div id="tower_info">
  {% if controllerinstall is defined and controllerinstall %}
  <div id="section_title">Automation controller</div>
  To login to the Automation controller WebUI use the following credentials:<br>
  <table>
  {% if dns_type != 'none' %}
    <tr>
  <td>WebUI link:</td>
  <td><a target=_blank href="https://student' . $student['id'] . '.{{ ec2_name_prefix }}.{{ workshop_dns_zone }}">https://student' . $student['id'] . '.{{ ec2_name_prefix }}.{{ workshop_dns_zone }}</a></td>
    </tr>
  {% endif %}
  {% if dns_type == 'none' %}
    <tr>
  <td>UI link:
  <td><a target=_blank href="https://' . $student['ip'] . '">https://' . $student['ip'] . '</a></td>
    </tr>
  {% endif %}
    <tr>
      <td>username:</td>
      <td><code>{% if workshop_type == "windows" %}student' . $student['id'] . '{% else %}admin{% endif %}</code></td>
    </tr>
    <tr>
      <td>password:</td>
      <td><code>{{admin_password}}</code></td>
    </tr>
  </table>
  {% endif %}
  {% if workshop_type == "configascode" %}
  <div id="section_title">Private automation hub</div>
  To login to the Private automation hub WebUI use the following credentials:<br>
  <table>
    <tr>
  <td>WebUI link:</td>
  <td><a target=_blank href="https://hub-student' . $student['id'] . '.{{ ec2_name_prefix }}.{{ workshop_dns_zone }}">https://hub-student' . $student['id'] . '.{{ ec2_name_prefix }}.{{ workshop_dns_zone }}</a></td>
    </tr>
    <tr>
      <td>username:</td>
      <td><code>admin</code></td>
    </tr>
    <tr>
      <td>password:</td>
      <td><code>{{admin_password}}</code></td>
    </tr>
  </table>
  {% endif %}
  {% if workshop_type == "smart_mgmt" %}
  <div id="section_title">Red Hat Satellite </div>
  To login to the Satellite WebUI use the following credentials:<br>
  <table>
  {% if dns_type != 'none' %}
    <tr>
  <td>WebUI link:</td>
  <td><a target=_blank href="https://student' . $student['id'] . '-sat.{{ ec2_name_prefix }}.{{ workshop_dns_zone }}">https://student' . $student['id'] . '-sat.{{ ec2_name_prefix }}.{{ workshop_dns_zone }}</a></td>
    </tr>
  {% endif %}
  {% if dns_type == 'none' %}
    <tr>
  <td>UI link:
  <td><a target=_blank href="https://' . $student['ip'] . '">https://' . $student['ip'] . '</a></td>
    </tr>
  {% endif %}
    <tr>
      <td>username:</td>
      <td><code>{% if workshop_type == "windows" %}student' . $student['id'] . '{% else %}admin{% endif %}</code></td>
    </tr>
    <tr>
      <td>password:</td>
      <td><code>{{admin_password}}</code></td>
    </tr>
  </table>
  {% endif %}
  {% if workshop_type == "auto_satellite" %}
  <div id="section_title">Red Hat Satellite </div>
  To login to the Satellite WebUI use the following credentials:<br>
  <table>
  {% if dns_type != 'none' %}
    <tr>
  <td>WebUI link:</td>
  <td><a target=_blank href="https://student' . $student['id'] . '-sat.{{ ec2_name_prefix }}.{{ workshop_dns_zone }}">https://student' . $student['id'] . '-sat.{{ ec2_name_prefix }}.{{ workshop_dns_zone }}</a></td>
    </tr>
  {% endif %}
  {% if dns_type == 'none' %}
    <tr>
  <td>UI link:
  <td><a target=_blank href="https://' . $student['ip'] . '">https://' . $student['ip'] . '</a></td>
    </tr>
  {% endif %}
    <tr>
      <td>username:</td>
      <td><code>{% if workshop_type == "windows" %}student' . $student['id'] . '{% else %}admin{% endif %}</code></td>
    </tr>
    <tr>
      <td>password:</td>
      <td><code>{{admin_password}}</code></td>
    </tr>
  </table>
  {% endif %}
  {% if workshop_type == "ripu" %}
  <div id="section_title">RHEL Web Console</div>
  To login to the RHEL web console on the AAP webUI use the following credentials:<br>
  <table>
  {% if dns_type != 'none' %}
    <tr>
  <td>WebUI link:</td>
  <td><a target=_blank href="https://student' . $student['id'] . '.{{ ec2_name_prefix }}.{{ workshop_dns_zone }}:9090">https://student' . $student['id'] . '.{{ ec2_name_prefix }}.{{ workshop_dns_zone }}:9090</a></td>
    </tr>
  {% endif %}
  {% if dns_type == 'none' %}
    <tr>
  <td>UI link:
  <td><a target=_blank href="https://' . $student['ip'] . ':9090">https://' . $student['ip'] . ':9090</a></td>
    </tr>
  {% endif %}
    <tr>
      <td>username:</td>
      <td><code>student</code></td>
    </tr>
    <tr>
      <td>password:</td>
      <td><code>{{admin_password}}</code></td>
    </tr>
  </table>
  {% endif %}
  </div>
  {% if workshop_type == 'devops' %} Lab Guide: <a target=_blank href="http://student' . $student['id'] . '.{{ ec2_name_prefix }}.{{ workshop_dns_zone }}:8888">http://student' . $student['id'] . '.{{ ec2_name_prefix }}.{{ workshop_dns_zone }}:8888</a><br>{% endif %}';
    print '<div id="hub_info">
    {% if automation_hub is defined and automation_hub|bool and workshop_type != 'configascode' %}
    <div id="section_title">Private automation Hub</div>
    To login to the Private Automation Hub WebUI use the following credentials:<br>
    <table>
      <tr>
    <td>WebUI link:
    <td><a target=_blank href="' . $student['hub'] . '">' . $student['hub'] . '</a></td>
      </tr>
      <tr>
        <td>username:</td>
        <td><code>{% if workshop_type == "windows" %}student' . $student['id'] . '{% else %}admin{% endif %}</code></td>
      </tr>
      <tr>
        <td>password:</td>
        <td><code>{{ admin_password }}</code></td>
      </tr>
    </table>
    {% endif %}
    </div>';
  {% if workshop_type == "windows" %}
  {% else %}
  print '<div id="section_title"><a data-toggle="collapse" href="#collapse1">SSH access-></a></div><div id="collapse1" class="panel-collapse collapse">
  As a backup option if VS Code Terminal is not sufficient, you can directly SSH to your control node:<br>
  <div id="control_node">
  <div id="login_info">
  <table>
    <tr>
      <td>username:</td>
      <td><code>{{ student_user }}</code></td>
    </tr>
    <tr>
      <td>password:</td>
      <td><code>' . $student['password'] . '</code></td>
    </tr>
    <tr>
      <td>IP Address:</td>
      <td><code>' . $student['ip'] . '</code></td>
    </tr>
  </table>
  </div>
  <div id="example_login">
  <pre><code>ssh {{ student_user }}@' . $student['ip'] . '</code></pre>
  {% if dns_type != 'none' %}
  DNS: student' . $student['id'] . '.{{ ec2_name_prefix }}.{{ workshop_dns_zone }}<br>
  <pre><code>ssh {{ student_user }}@student' . $student['id'] . '.{{ ec2_name_prefix }}.{{ workshop_dns_zone }}</code></pre>
  {% endif %}
  </div>
  </div>
  </div>';
  {% endif %}

  print "</div></div>";

}





function isValidEmail($email){
    return filter_var($email, FILTER_VALIDATE_EMAIL) !== false;
}

function sql_clean_username($text) {
  $text = preg_replace("/[^[:alnum:][:space:] @\.\-_]/u", '', $text);
  return $text;
}

function db_execute($query) {
  global $db;
  $stmt = $db->query($query);
  return $db->lastInsertId();
}

function db_execute_prepare($query, $data) {
  global $db;
  $stmt = $db->prepare($query);
  $stmt->execute($data);
  return $db->lastInsertId();
}

function db_fetch_cell($query, $cell) {
  global $db;
  $stmt = $db->query($query);
  if (!$stmt) return false;
  $results = $stmt->fetch(\PDO::FETCH_ASSOC);
  if (!isset($results[$cell])) return false;
  return $results[$cell];
}

function db_fetch_assoc($query) {
  global $db;
  $stmt = $db->query($query);
  if ($stmt) {
    $results = $stmt->fetch(\PDO::FETCH_ASSOC);
    return $results;
  } else {
    return false;
  }
}

function db_fetch_assoc_prepare($query, $data) {
  global $db;
  $stmt = $db->prepare($query);
  $stmt->execute($data);
  $results = $stmt->fetch(\PDO::FETCH_ASSOC);
  return $results;
}

function db_fetch_assocs($query) {
  global $db;
  $stmt = $db->query($query);
  if ($stmt) {
    $results = $stmt->fetchAll(\PDO::FETCH_ASSOC);
    return $results;
  } else {
    return false;
  }
}

function db_fetch_assocs_prepare($query, $data) {
  global $db;
  $stmt = $db->prepare($query);
  $stmt->execute($data);
  $results = $stmt->fetchAll(\PDO::FETCH_ASSOC);
  return $results;
}

function display_form() {
  print "<div class='student_logins'>
    <div class='header'>
             <p class='studentinfo'>Please enter your Name and Email address.</p>
    </div>
      <div class='content'>
        <p>";
  print "<form action='/' method=POST enctype='multipart/form-data'>";
  print "<table><tr><td align=right>Name: </td><td><input type=text name=name size=20></td></tr>";
  print "<tr><td align=right>Email: </td><td><input type=text name=email size=20></td></tr>";
  print "<tr><td></td><td><input type=submit value='Submit'></td></tr></table></form>";
  print "</p>";
  print "</div></div>";
}